package com.itheima.d2_buffered_stream;

import java.io.*;

/**
 * 目标：掌握字节缓冲流的作用。
 */
public class Test1BufferedInputStream {
    public static void main(String[] args) throws IOException {

        File src = new File("day09file-io-app/image01/R-C.jpg");

        File file = new File("day09file-io-app/image03/R-C.jpg");

        copyFile(src,file);
    }
    public static void copyFile(File src,File file) throws IOException {
        try (FileInputStream fis = new FileInputStream(src);
             FileOutputStream fos = new FileOutputStream(file);
             BufferedInputStream bis = new BufferedInputStream(fis);
             final BufferedOutputStream bos = new BufferedOutputStream(fos))
        {
            byte[] buf = new byte[1024];
            int len;
            while ((len= bis.read(buf))!=-1){
                bos.write(buf,0,len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
